package com.ieng.kican.modules.security.utils;

import com.ieng.kican.modules.security.domain.JwtAuthUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class SecurityUtils {

    public static String username() {
        return current().getUsername();
    }

    public static JwtAuthUser current() {
        return (JwtAuthUser) getAuthentication().getPrincipal();
    }

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static boolean matchesPass(String text1, String text2) {
        return new BCryptPasswordEncoder().matches(text1, text2);
    }

    public static String encodePass(String text) {
        return new BCryptPasswordEncoder().encode(text);
    }

}
